package cifg;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.iid.flappybird.R;


public class DCFAEB {

    private Context mContext;
    private Dialog dialog;
    private View parentView;
    private TextView tv_title;
    private TextView tv_msg;
    private TextView tv_neg;
    private TextView tv_pos;
    private ImageView click_close;
    private boolean ClickBlankCancellation = true;
    private boolean otherCancellation = false;

    public DCFAEB(Context context) {
        this.mContext = context;
    }

    @SuppressLint("InflateParams")
    public DCFAEB init() {
        parentView = LayoutInflater.from(mContext).inflate(R.layout.rule_dialog_layout, null);
        tv_title = parentView.findViewById(R.id.tv_title);
        tv_msg = parentView.findViewById(R.id.tv_msg);
        tv_neg = parentView.findViewById(R.id.tv_neg);
        tv_pos = parentView.findViewById(R.id.tv_pos);
        click_close = parentView.findViewById(R.id.click_close);

        dialog = new Dialog(mContext, R.style.AlertDialogStyle);
        dialog.setContentView(parentView);

        parentView.setLayoutParams(new FrameLayout.LayoutParams((int) (DCFAFL.getScreenWidth(mContext) * 0.8), (int) (DCFAFL.getScreenHeight(mContext) * 0.7)));
        return this;
    }

    public DCFAEB setClickBlankCancellation(boolean ClickBlankCancellation) {
        this.ClickBlankCancellation = ClickBlankCancellation;
        return this;
    }

    // 0 游戏规则 1 隐私政策
    public DCFAEB setLayout() {
        String en_privacyPolicy = "<pre>\n" +
                "<p><strong>Privacy Policy</strong></p>\n" +
                "\n" +
                "<p>Thank you for using our AnimalEscapePlan game (hereinafter referred to as the \"Game\"). This privacy policy will explain how we handle and protect your personal information in the Game. Please read this privacy policy carefully before using the Game.</p>\n" +
                "\n" +
                "<p><strong>1. Information Collection and Use</strong></p>\n" +
                "\n" +
                "<p>&emsp;<strong>1.1 Game Data</strong></p>\n" +
                "\n" +
                "<p>&emsp;&emsp;Our Game does not actively collect any personally identifiable information. However, in order to provide the online game progress and score synchronization feature, we may collect and store your game progress and scores for the purpose of restoring your data when you use different devices or reinstall the Game. This data is only used for the purpose of game progress synchronization and will not be shared with any third parties.</p>\n" +
                "\n" +
                "<p><strong>2. Information Storage and Protection</strong></p>\n" +
                "\n" +
                "<p>&emsp;We take reasonable security measures to protect your personal information from unauthorized access, use, or disclosure. We use industry-standard security measures to protect your data, including encrypted transmission and storage of data.</p>\n" +
                "\n" +
                "<p><strong>3. Third-Party Services</strong></p>\n" +
                "\n" +
                "<p>&emsp;Our Game may use third-party services to help us provide a better gaming experience and functionality. These third-party services may collect and use your information solely for the purpose of providing relevant services to us. Please note that the use of these third-party services is subject to their own privacy policies.</p>\n" +
                "\n" +
                "<p><strong>4. Other Links</strong></p>\n" +
                "\n" +
                "<p>&emsp;Our Game may contain links to other websites or services that may have their own independent privacy policies. We do not assume any responsibility for the accuracy, completeness, and security of the content of these links. When accessing these links, you should review the respective privacy policies.</p>\n" +
                "\n" +
                "<p><strong>5. Legal Requirements</strong></p>\n" +
                "\n" +
                "<p>&emsp;We may disclose your personal information in response to applicable legal requirements or government requests. We reserve the right to disclose your personal information as required by law.</p>\n" +
                "\n" +
                "<p><strong>6. Updates to the Privacy Policy</strong></p>\n" +
                "\n" +
                "<p>&emsp;We may update this privacy policy from time to time to reflect changes in the Game and developments in law, technology, and the industry. We will announce the updated privacy policy within the Game and encourage you to periodically review it to stay informed about the latest changes.</p>\n" +
                "\n" +
                "<p><strong>7. Contact Us</strong></p>\n" +
                "\n" +
                "<p>&emsp;If you have any questions or concerns about this privacy policy or your personal information, please contact us by sending an email to aaaa@gmail.com.</p>\n" +
                "</pre>";

        tv_title.setText( mContext.getString(R.string.PrivacyPolicy));
        tv_msg.setText(Html.fromHtml(en_privacyPolicy, Html.FROM_HTML_MODE_COMPACT));

        click_close.setOnClickListener((view -> {
            if (dialog != null && dialog.isShowing()) {
                otherCancellation = true;
                dialog.dismiss();
                dialog = null;
            }
        }));
        return this;
    }


    public void show() {
        if (mContext instanceof Activity) {
            Activity activity = (Activity) mContext;
            if (!activity.isFinishing()) {
                dialog.setCanceledOnTouchOutside(ClickBlankCancellation);
                dialog.show();
            }
        }
    }
}
